/**
 * 
 */
package com.thor.palmmall.rest.chart;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.thor.commons.exception.ThorServiceException;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.chart.converter.AAppMainReportConverter;
import com.thor.palmmall.rest.chart.converter.AMaintainRepairDataConverter;
import com.thor.palmmall.rest.chart.converter.AMaintainReportDataConverter;
import com.thor.palmmall.rest.chart.converter.AMonitorReportConverter;
import com.thor.palmmall.rest.chart.converter.AOrdinarySalesTypeConverter;
import com.thor.palmmall.rest.chart.converter.APassengersReportConverter;
import com.thor.palmmall.rest.chart.converter.AReceiptReportConverter;
import com.thor.palmmall.rest.chart.converter.ARentalReportConverter;
import com.thor.palmmall.rest.chart.converter.ASalesReportConverter;
import com.thor.palmmall.rest.chart.converter.ASalesTypeConverter;
import com.thor.palmmall.rest.chart.converter.SChartParamConverter;
import com.thor.palmmall.rest.chart.converter.SLoginInfoConverter;
import com.thor.palmmall.rest.chart.converter.SMaintainReportConditionConverter;
import com.thor.palmmall.rest.chart.converter.SMonitorParamConverter;
import com.thor.palmmall.rest.chart.converter.SOrdinarySalesTypeParamConverter;
import com.thor.palmmall.rest.chart.converter.SPassengersReportParamConverter;
import com.thor.palmmall.rest.chart.converter.SReceiptReportConverter;
import com.thor.palmmall.rest.chart.converter.SRentalParamConverter;
import com.thor.palmmall.rest.chart.converter.SSalesInputReportConditionConverter;
import com.thor.palmmall.rest.chart.converter.SSalesTypeParamConverter;
import com.thor.palmmall.rest.sales.input.converter.ASalesTotalReportConverter;
import com.thor.palmmall.spi.chart.SAppMainReport;
import com.thor.palmmall.spi.chart.SChartService;
import com.thor.palmmall.spi.chart.SMaintainCategoryData;
import com.thor.palmmall.spi.chart.SMaintainRepairData;
import com.thor.palmmall.spi.chart.SMaintainReportData;
import com.thor.palmmall.spi.chart.SMonitorReport;
import com.thor.palmmall.spi.chart.SOrdinarySalesType;
import com.thor.palmmall.spi.chart.SPassengersReport;
import com.thor.palmmall.spi.chart.SReceiptReport;
import com.thor.palmmall.spi.chart.SRentalReport;
import com.thor.palmmall.spi.chart.SSalesReport;
import com.thor.palmmall.spi.chart.SSalesReportData;
import com.thor.palmmall.spi.chart.SSalesType;
import com.thor.palmmall.spi.common.SResponse;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class AChartServiceImpl implements AChartService {

  @Override
  public AMonitorReport getMoitorReport(AMonitorParam monitorParam) throws ThorServiceException {
    SResponse<SMonitorReport> resp = sChartService
        .getMoitorReport(SMonitorParamConverter.getInstance().convert(monitorParam));
    if (resp.isSuccess()) {
      return AMonitorReportConverter.getInstance().convert(resp.getBody());
    } else {
      throw new ThorServiceException("无法监控页面报表信息：" + resp.getMessage());
    }
  }

  @Override
  public List<AAppMainReport> getStoreReport(ALoginInfo loginInfo) throws ThorServiceException {
    SResponse<List<SAppMainReport>> resp = sChartService
        .getStoreReport(SLoginInfoConverter.getInstance().convert(loginInfo));
    if (resp.isSuccess()) {
      return ConverterUtil.convert(resp.getBody(), AAppMainReportConverter.getInstance());
    } else {
      throw new ThorServiceException("无法获得首页项目报表信息：" + resp.getMessage());
    }

  }

  @Override
  public List<ASalesReport> getSalesReport(AChartParam chartParam) throws ThorServiceException {
    SResponse<List<SSalesReport>> resp = sChartService
        .getSalesReport(SChartParamConverter.getInstance().convert(chartParam));
    if (resp.isSuccess()) {
      return ConverterUtil.convert(resp.getBody(), ASalesReportConverter.getInstance());
    } else {
      throw new ThorServiceException("无法获得销售客流报表信息：" + resp.getMessage());
    }
  }

  @Override
  public ARentalReport getRentalReport(ARentalParam rentalParam) throws ThorServiceException {
    SResponse<SRentalReport> resp = sChartService
        .getRentalReport(SRentalParamConverter.getInstance().convert(rentalParam));
    if (resp.isSuccess()) {
      return ARentalReportConverter.getInstance().convert(resp.getBody());
    } else {
      throw new ThorServiceException("无法获得业态租赁报表信息：" + resp.getMessage());
    }
  }

  @Override
  public AReceiptReport getReceiptReport(AReceiptParam receiptParam) throws ThorServiceException {
    SResponse<SReceiptReport> resp = sChartService
        .getReceiptReport(SReceiptReportConverter.getInstance().convert(receiptParam));
    if (resp.isSuccess()) {
      return AReceiptReportConverter.getInstance().convert(resp.getBody());
    } else {
      throw new ThorServiceException("无法获得收缴率报表信息：" + resp.getMessage());
    }
  }

  @Override
  public List<ASalesType> getSalesReportType(ASalesTypeParam salesTypeParam)
      throws ThorServiceException {
    SResponse<List<SSalesType>> resp = sChartService
        .getSalesReportType(SSalesTypeParamConverter.getInstance().convert(salesTypeParam));
    if (resp.isSuccess()) {
      return ConverterUtil.convert(resp.getBody(), ASalesTypeConverter.getInstance());
    } else {
      throw new ThorServiceException("无法获取业态/楼层销售统计报表信息：" + resp.getMessage());
    }
  }

  @Override
  public AOrdinarySalesType getOrdinarySalesReportType(AOrdinarySalesTypeParam salesTypeParam)
      throws ThorServiceException {
    SResponse<SOrdinarySalesType> resp = sChartService.getOrdinarySalesReportType(
        SOrdinarySalesTypeParamConverter.getInstance().convert(salesTypeParam));
    if (resp.isSuccess()) {
      return AOrdinarySalesTypeConverter.getInstance().convert(resp.getBody());
    } else {
      throw new ThorServiceException("无法获取业态/楼层销售普通报表信息：" + resp.getMessage());
    }
  }

  @Override
  public List<APassengersReport> getPassengersReport(APassengersReportParam pasParam)
      throws ThorServiceException {
    SResponse<List<SPassengersReport>> resp = sChartService
        .getPassengersReport(SPassengersReportParamConverter.getInstance().convert(pasParam));
    if (resp.isSuccess()) {
      return ConverterUtil.convert(resp.getBody(), APassengersReportConverter.getInstance());
    } else {
      throw new ThorServiceException("无法获取客流分布报表信息：" + resp.getMessage());
    }

  }

  @Override
  public List<ASalesReportData> getSalesReport(ASalesInputReportCondition condition)
      throws ThorServiceException {
    SResponse<List<SSalesReportData>> resp = sChartService
        .getSalesReport(SSalesInputReportConditionConverter.getInstance().convert(condition));
    if (resp.isSuccess())
      return ConverterUtil.convert(resp.getBody(), ASalesTotalReportConverter.getInstance());
    else
      throw new ThorServiceException("没有查询销售报表数据：" + resp.getMessage());
  }

  @Override
  public AMaintainReportData maintainReport(AMaintainReportCondition condition)
      throws ThorServiceException {
    SResponse<SMaintainReportData> resp = sChartService
        .getMaintainReport(SMaintainReportConditionConverter.getInstance().convert(condition));
    if (resp.isSuccess())
      return AMaintainReportDataConverter.getInstance().convert(resp.getBody());
    else
      throw new ThorServiceException("没有查询到维修统计报表数据：" + resp.getMessage());
  }

  @Override
  public List<AMaintainRepairData> getRepairReport(AMaintainReportCondition condition)
      throws ThorServiceException {
    SResponse<List<SMaintainRepairData>> resp = sChartService
        .getRepairReport(SMaintainReportConditionConverter.getInstance().convert(condition));
    if (resp.isSuccess())
      return ConverterUtil.convert(resp.getBody(), AMaintainRepairDataConverter.getInstance());
    else
      throw new ThorServiceException("没有查询到维修员维修报表：" + resp.getMessage());
  }

  @Override
  public List<AMaintainCategoryData> getCategoryReport(AMaintainReportCondition condition) {
    SResponse<List<SMaintainCategoryData>> resp = sChartService
        .getCategoryReport(SMaintainReportConditionConverter.getInstance().convert(condition));
    if (resp.isSuccess()) {
      return ConverterUtil.convert(resp.getBody(), AMaintainCategoryDataConverter.getInstance());
    } else {
      return null;
    }
  }

  @Autowired
  private SChartService sChartService;

}
